package com.example.bili.view.fragment;

import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.bili.R;
import com.example.bili.allbean.MyinfoBean;
import com.example.bili.base.BaseFragment;
import com.example.bili.module.OkHttp;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.Gson;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Request;

import static com.example.bili.internet.connectors.MYINFO;

/**
 * Created by Administrator on 2017/3/9. 侧拉页面
 */

public class D_DrawLayout extends BaseFragment implements OkHttp.DataCallBack {
    private SimpleDraweeView face;
    private TextView name;
    private TextView members;
    private TextView coin;


    @Override
    protected void initview(View view) {
        face = (SimpleDraweeView) view.findViewById(R.id.d_drawlayout_myimg_fresco);
        name = (TextView) view.findViewById(R.id.d_drawlayout_name_tv);
        members = (TextView) view.findViewById(R.id.d_drawlayout_members_tv);
        coin = (TextView) view.findViewById(R.id.d_drawlayout_coin_tv);
    }

    @Override
    protected void m_onCreateView() {
        //请求数据
        getdata();
    }

    @Override
    public View getLayoutview() {
        return View.inflate(getActivity(), R.layout.d_drawlayout, null);
    }

    public void getdata() {
        //设置请求参数
        Map<String, String> map = new HashMap<>();
        map.put("mid", "775");
        //网络请求
        OkHttp.postAsync(MYINFO, map, this);
    }


    @Override
    public void requestFailure(Request request, IOException e) {
        Toast.makeText(getActivity(), "请求失败", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void requestSuccess(String result) throws Exception {
        MyinfoBean myinfoBean = new Gson().fromJson(result, MyinfoBean.class);
        //控件赋值
        face.setImageURI(myinfoBean.getCard().getFace());
        String s = myinfoBean.getCard().getName() + "  lv:" + myinfoBean.getCard().getLevel_info().getCurrent_level();
        name.setText(s);
        if (myinfoBean.getCard().isApprove()) {
            members.setText("正式会员");
        } else {
            members.setText("大众会员");
        }
        coin.setText("硬币: "+myinfoBean.getCard().getCoins());
    }
}
